package cn.cdeden.knowledge.dubbo;

import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.knowledge.api.domain.RemoteEnterpriseFilesTreeService;
import cn.cdeden.knowledge.api.domain.vo.EnterpriseFilesTreeRemoteVo;
import cn.cdeden.knowledge.domain.EnterpriseFilesTree;
import cn.cdeden.knowledge.service.EnterpriseFilesTreeService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
@RequiredArgsConstructor
public class RemoteEnterpriseFilesTreeServiceImpl implements RemoteEnterpriseFilesTreeService {

    private final EnterpriseFilesTreeService enterpriseFilesTreeService;

    @Override
    public EnterpriseFilesTreeRemoteVo getById(String parentId) {
        EnterpriseFilesTree byId = enterpriseFilesTreeService.getById(Long.valueOf(parentId));
        return MapstructUtils.convert(byId, EnterpriseFilesTreeRemoteVo.class);
    }

    @Override
    public EnterpriseFilesTreeRemoteVo nameRechecking(String realName, String parentId, String suffix) {
        EnterpriseFilesTree enterpriseFilesTree = enterpriseFilesTreeService.nameRechecking(realName, parentId, suffix);
        return MapstructUtils.convert(enterpriseFilesTree, EnterpriseFilesTreeRemoteVo.class);
    }

    @Override
    public Boolean saveBatch(List<EnterpriseFilesTreeRemoteVo> filesTrees) {
        return enterpriseFilesTreeService.saveBatch(MapstructUtils.convert(filesTrees, EnterpriseFilesTree.class));
    }

    @Override
    public boolean updateEs(String id, String esID) {

        return enterpriseFilesTreeService.lambdaUpdate()
            .eq(EnterpriseFilesTree::getId, id)
            .set(EnterpriseFilesTree::getEsId,esID)
            .update();
    }
}
